package com.leps.nq.common.vo;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
@ApiModel
public class BaseQueryModel {
    private String keyword;
    private Date beginDate;
    private Date endDate;
    @ApiModelProperty("页码，默认为1")
    private Long pageNum = 1L;
    @ApiModelProperty("每页条数，默认为10")
    private Long pageSize = 10L;
    @ApiModelProperty("排序字段名")
    private String sortColumn;
    @ApiModelProperty("排序顺序(asc|ascending, desc|descending)")
    private String order = " ASC ";

    public void setOrder(String order) {
        if(order == null || order.isEmpty() || "asc".equalsIgnoreCase(order) || "ascending".equalsIgnoreCase(order)) {
            this.order = " ASC ";
        } else {
            this.order = " DESC ";
        }
    }

    public void setSortColumn(String sortColumn) {
        this.sortColumn = StrUtil.toUnderlineCase(sortColumn);
    }

    @ApiModelProperty(hidden = true)
    public String getOrderBy() {
        if(StrUtil.isBlank(this.sortColumn)) return null;
        return StrUtil.format(" ORDER BY {} {} ", this.sortColumn, this.order);
    }
}
